<?php

class Core_Backend_Component_Media_View_Video_Index extends Core_Backend_Share_View_Grid {

    public function __construct() {
        parent::__construct();
    }

    protected function buildNavigation($navigation) {
        $navigation->addLabel($this->__('media.title.video_index'));
        parent::buildNavigation($navigation);
    }

    protected function buildToolbar($toolbar) {
    	parent::buildToolbar($toolbar);
        if ($this->getIdentity()->isAllowAction('media_video_review')) {
            $group = $toolbar->createGroup('status');
            $group->addButton($this->__('share.button.publish'))
                    ->bindEvent('click', "submitGridChecked('" . $this->getGrid()->getId() . "', '" . $this->getUrl(array('status'=>'published'), 'review') . "')");
            $group->addButton($this->__('share.button.forbid'))
                    ->bindEvent('click', "forbidGridChecked('" . $this->getGrid()->getId() . "', '" . $this->getUrl(array('status'=>'forbidden'), 'review') . "')");
        }
    	$group = $toolbar->createGroup();
        $group->addLink($this->getUrl(array('areaid'=>$this->getCurrentAreaId()), 'create'), $this->__('share.button.create'));
    }

    protected function buildGrid($grid) {
        $filter = new Kd_Object($this->getRequest()->getParameter('filter'));
    	$grid->setId('video_grid')
                ->setPrimaryKey('id')
                ->setAllowFilter(TRUE)
                ->setSortField($this->getRequest()->getParameter('sort', 'id'))
                ->setSortDirection($this->getRequest()->getParameter('dir', 'asc'));
        $grid->addLabelColumn($this->__('share.label.name'), 'name', '{name}')
                ->setTextboxFilter(NULL, NULL, $filter->getData('name'))
                ->setSortField('name')
                ->setWidth(200);
        $grid->addLabelColumn($this->__('share.label.url'), 'url', '{url}');
        $grid->addLabelColumn($this->__('share.label.status'), 'status', '{status}')
                ->setWidth(80);
        $grid->addLabelColumn($this->__('share.label.mender'), 'mender', '{mender_name}')
                ->setTextboxFilter(NULL, NULL, $filter->getData('mender_name'))
                ->setSortField('mender')
                ->setWidth(100);
        $grid->addLinkColumn('#', 'edit', $this->getUrl(array('id' => '{id}'), 'edit'), $this->__('share.button.edit'))
                ->setWidth(40)
                ->setAlign('center');
        $grid->setDataSource($this->getList()->toArray());
        parent::buildGrid($grid);
    }

    protected function buildPagination($pagination) {
        $pagination->setUrlFormat($this->getPaginationUrl())->setRecordCount($this->getRecords());
        parent::buildPagination($pagination);
    }

}